package com.example.cdctest.service.impl;

import com.example.cdctest.mapper.CategoryMapper;
import com.example.cdctest.pojo.Category;
import com.example.cdctest.service.CategoryService;
import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)
public class CategoryServiceImpl implements CategoryService {

    @Resource
    private CategoryMapper categoryMapper;

    //添加问题类别
    @Override
    public void insert(Category object) {
        categoryMapper.insert(object);
    }


    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(String ids) {

    }

    @Override
    public void update(Category object) {

    }

    @Override
    public Category findById(Integer id) {
        return null;
    }

    //从数据库取出所有的类别信息
    @Override
    @Cacheable(value = "questionTypeCache",key = "'getAllCategory'")
    public List<Category> findAll() {
        return categoryMapper.findAllCategory();
    }

    @Override
    public PageInfo<Category> findPage(int pageSize) {
        return null;
    }

    //从数据库中查出类别的总数据
    @Override
    public int getCategory() {
        return categoryMapper.findCategoryCount();
    }

    //问题的禁用和解封
    @Override
    public void updateCategory(Integer id) {
        categoryMapper.updateCategory(id);
    }

    //清除缓存
    @Override
    @CacheEvict(value = "questionTypeCache",allEntries = true)
    public void clearCache() {

    }

    @Override
    public List<Category> specialExercises() {
        return categoryMapper.specialExercises();
    }


}
